package com.imooc.autoconfigure;

import com.imooc.support.CurrentMethodAndClassDataSourceResolver;
import com.imooc.support.DataSourceClassResolver;
import com.imooc.support.MethodAndInterfaceDataSourceResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

/**
 * 解析数据源的自动装配类
 * <pre>
 *     查找类或者方法上指定的注解，并获取注解上的属性
 *     这里用的自定义注解@DDS(value="")
 * </pre>
 *
 * @author tom
 */
@Configuration
public class DynamicDataSourceClassResolverAutoConfiguration {

    /**
     * 解析数据源列表
     *
     * @return {@link DataSourceClassResolver} 数据源类型解析器
     */
    @Bean
    public List<DataSourceClassResolver> dataSourceClassResolvers() {
        List<DataSourceClassResolver> resolvers = new ArrayList<>();
        resolvers.add(new CurrentMethodAndClassDataSourceResolver());
        resolvers.add(new MethodAndInterfaceDataSourceResolver());
        return resolvers;
    }
}
